﻿using ASmile.Com;
using ASmile.DBModel;
using ASmile.Win.Extend;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ASmile.Win.Forms
{
    public partial class FrmUser : FrmBase
    {
        public FrmUser()
        {
            InitializeComponent();
        }

        IUserManageBLL BLLObj { get; } = ObjectFactory.GetObject<IUserManageBLL>("UserManageBLL");

        private void FrmUser_Load(object sender, EventArgs e)
        {
            var crud = new FormCrudEx<Sys_User>
            {
                BLLObj = BLLObj,
                BtnAdd = tsBtnAdd,
                BtnAddCopy = tsBtnCopyAdd,
                BtnADSearch = tsAdSearch,
                BtnDel = tsBtnDelete,
                BtnSearch = tsBtnSearch,
                BtnEdit = tsBtnEdit,
                Dgv = dgv,
                Owner = this,
                PageNav = ucPageNav1,
                TxtSearch = tsTxtSearch,
                CreateAddForm = CreateEditForm,
                OnSearchBefore = QueryBefore,
                OnSearchAfter = QueryAfter
            };
            crud.Init();
        }
        FrmUserEdit CreateEditForm()
        {
            return new FrmUserEdit();
        }

        void QueryBefore(ArgPageData arg)
        {            
            //arg.SearchVal = tsTxtSearch.Text;
        }

        void QueryAfter(object sender)
        {
            var query = sender as FormQuery<ArgPageData, Sys_User>;
            if (dgv.DataSource == null)
            {
                dgv.DataSource = new List<Sys_User>();
            }
        }

        private void tsbtnExit_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
